<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <title>南方电网掌上乌当App下载</title>
  <style type="text/css">
    div.hidden {
      display: none;
    }

    .button {
      height: 30px;
      border-radius: 20px;
      color: #FFF;
      line-height: 30px;
      text-align: center;
      font-size: 14px;
      display: inline-block;
      padding: 0 10px;
      margin: 10px;
      float: left;
    }

    .hidden {
      display: none;
    }

    .gary {
      background-color: #E6E6E6 !important;
    }

  </style>
  <script type="text/javascript">
    function isWeiXin() {
      var ua = window.navigator.userAgent.toLowerCase();
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        return true;
      } else {
        return false;
      }
    }

    function getQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return 'dev';
    }

    function hasClass(elements, cName) {
      return !!elements.className.match(new RegExp("(\\s|^)" + cName + "(\\s|$)")); // ( \\s|^ ) 判断前面是否有空格 （\\s | $ ）判断后面是否有空格 两个感叹号为转换为布尔值 以方便做判断
    }

    function removeClass(elements, cName) {
      if (hasClass(elements, cName)) {
        elements.className = elements.className.replace(new RegExp("(\\s|^)" + cName + "(\\s|$)"), " "); // replace方法是替换
      }
    }

    // 获取终端的相关信息
    var Terminal = {
      // 辨别移动终端类型
      platform: function () {
        var u = navigator.userAgent,
          app = navigator.appVersion;
        return {
          // android终端或者uc浏览器
          android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1,
          // 是否为iPhone或者QQHD浏览器
          iPhone: u.indexOf('iPhone') > -1,
          // 是否iPad
          iPad: u.indexOf('iPad') > -1
        };
      }(),
      // 辨别移动终端的语言：zh-cn、en-us、ko-kr、ja-jp...
      language: (navigator.browserLanguage || navigator.language).toLowerCase()
    };

    // 根据不同的终端，跳转到不同的地址
    var env = getQueryString('env');
    //Android
    var devAndroidUrl =
      'https://weixin.wuxiyi.com/app/repository/Nanwang-app-repo-dev/WudangApp/android-armv7-release/latest/android-armv7-release-latest.apk';
    
    var proAndroidUrl =
      'https://weixin.wuxiyi.com/app/repository/Nanwang-app-repo-release/WudangApp/android-armv7-release/latest/android-armv7-release-latest.apk';

    var testAndroidUrl =
      'https://weixin.wuxiyi.com/app/repository/Nanwang-app-repo-stage/WudangApp/android-armv7-release/latest/android-armv7-release-latest.apk';

    //iOS
    var appstoreLink =
      'itms-services:///?action=download-manifest&url=https://weixin.wuxiyi.com/app/repository/Wudang-app-repo-release/WudangApp/manifest/release/manifest-release.plist';
    var iosTestUrl =
      'itms-services:///?action=download-manifest&url=https://weixin.wuxiyi.com/app/repository/Wudang-app-repo-release/WudangApp/manifest/stage/manifest-stage.plist';
    var iosDevUrl =
      'itms-services:///?action=download-manifest&url=https://weixin.wuxiyi.com/app/repository/Wudang-app-repo-release/WudangApp/manifest/dev/manifest-dev.plist'
                                                
    var theUrl;
    window.onload = function () {
      if (Terminal.platform.android) {
        if (env == "prod") {
          theUrl = proAndroidUrl;
        } else if (env == "test") {
          theUrl = testAndroidUrl;
        } else if (env == "dev") {
          theUrl = devAndroidUrl;
        }
      } else if (Terminal.platform.iPhone) {
        if (env == 'test') {
          theUrl = iosTestUrl;
        } else if (env == "prod") {
          theUrl = appstoreLink;
        }
      }
      if (theUrl) {
        location.href = theUrl;
      }
    };

    function download(type) {
      if (type === 'dev') {
        theUrl = devAndroidUrl;
      } else if (type === 'iosTest') {
        theUrl = iosTestUrl;
      } else if (type === 'test') {
        theUrl = testAndroidUrl
      } else if (type === 'prod') {
        theUrl = proAndroidUrl;
      } else if (type === 'iosStore') {
        theUrl = appstoreLink;
      } else if (type == 'iosDev') {
        theUrl = iosDevUrl;
      } else if (type == 'test-hotfix') {
        theUrl = testHotFixAndroidUrl;
      } else if (type == 'iosTestHotfix') {
        theUrl = iosTestHotFixUrl;
      } else {
        return;
      }
      location.href = theUrl;
    }

    function onReady(fn) {
      var readyState = document.readyState;
      if (readyState === 'interactive' || readyState === 'complete') {
        fn()
      } else {
        window.addEventListener("DOMContentLoaded", fn);
      }

    }
    onReady(function () {
      var buttons = document.getElementsByClassName("button");
      // 根据不同的终端，跳转到不同的地址
      if (env && (env === "dev" || env === "mock" || env === "test")) {
        for (var i = 0; i < buttons.length; i++) {
          removeClass(buttons[i], "hidden");
        }
      }
    })

  </script>
</head>

<body>
  <!--<div id="downloadClick" class="hidden">
    <a href="itms-services:///?action=download-manifest&url=https://120.78.83.127/nexus/repository/Recruit-app-repo-stage/RecruitApp/manifest/latest/manifest-latest.plist">app下载</a>
  </div>-->

  <div>
    <div>安卓环境：</div>
    <div class="button hidden" style="background-color: rgb(168, 212, 230)" onclick="download('dev')">开发dev环境----app下载</div>
    <div class="button hidden" style="background-color: rgb(36, 52, 114)" onclick="download('test')">测试test环境----app下载</div>
    <div class="button" style="background-color: #D9B3E6" onclick="download('prod')">线上prod环境----app下载</div>
  </div>
  <div style="clear: both;">
    <div>ios环境：</div>
    <div class="button" style="background-color: rgb(168, 212, 230)" onclick="download('iosStore')">生产app下载</div>
    <div class="button hidden" style="background-color: rgb(36, 52, 114)" onclick="download('iosTest')">测试app下载</div>
    <div class="button hidden" style="background-color: #D9B3E6" onclick="download('iosDev')">开发app下载</div>
  </div>
</body>

</html>
